function showCertificationSearch() {
	window.location.href = "showCertificationSearch.do";
}

function ajaxFindCertificationSearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxCertificationSearchList.do",
		data : {
			certificatecode:$("#txtCertificateCode").val(),
			verificationunit:$("#txtVerificationUnit").val(),
			controlid:$("#txtControlId").val(),
			standard:$("#txtStandard").val(),
			certificatedate:$("#certificateDate").val(),
			expiredate:$("#expireDate").val(),
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listcertificationBox").html(msg);
		}
	});
}

function ajaxShowCertificationEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowCertificationEdit.do",
		data:{certificationId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 640,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveCertification(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}

function ajaxShowCertificationView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowCertificationView.do",
		data:{certificationId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 640,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxSaveCertification(objDialog) {
	certificationValidate();
	if ($("#frmCertification").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveCertification.do",
				success: function (msg) {
					clearInput("#sltCertification");
					ajaxFindCertificationSearchList();
					showMessageDialog("保存检定","检定信息保存成功。",null,dialogType.info);
				}
		};
		$("#frmCertification").ajaxSubmit(options);
	}
}

function ajaxDeleteCertificationById(id) {
	var certificationIds="";
	var sltCFT = $("#listCertificationList tbody input:checked").length;
	if(id==null){
		$("#listCertificationList tbody input:checked").each(function(){ 
			certificationIds += $(this).val()+";";
		});
		if(sltCFT == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			certificationIds = certificationIds.substring(0, certificationIds.length-1);
		} 
	}else{
		certificationIds=id;
		sltCFT = 1;
	}
	if(certificationIds!=null){
		showMessageDialog("删除检定信息","确定要删除所选"+sltCFT+"条检定信息记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteCertificationByIds.do",
				data:{certificationIds:certificationIds},
				success:function(msg){
					ajaxFindCertificationSearchList();
					showMessageDialog("提示","检定信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function certificationValidate(){
	$("#frmCertification").validate({
		rules : {
			certificatecode: "required",
			verificationunit:"required"
		},
		messages: {
			certificatecode: "检定证号不能为空！",
			verificationunit: "检定单位不能为空！"
		},
	});
}
